package homework8_2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class work2 {

	final static String url = "jdbc:mysql://localhost:3306/java61?useSSL=false";
	final static String user = "root";
	final static String password = "123456";

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		// Class.forName("java_dabc.A");
		Connection con = null;
		Statement stm = null;
		Scanner in = new Scanner(System.in);
		try {
			con = DriverManager.getConnection(url, user, password);
			System.out.println(con.getClass().getName());
			stm = con.createStatement();
			// System.out.println("请输入课程id");
			// String a0 = in.next();
			System.out.println("请输入学号");
			int a1 = in.nextInt();
			System.out.println("请输入姓名");
			String a2 = in.next();
			System.out.println("请输入电话");
			String a3 = in.next();
			System.out.println("请输入入学时间");
			String date = in.next();
			SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
			Date a4 = (Date) df.parseObject(date);
			String sql = "INSERT INTO s_student(subjectname,classhour,gradeid,active)VALUES ('" + a1 + "'," + a2 + ","
					+ a3 + "," + a4 + ") ";
			int r = stm.executeUpdate(sql);
			System.out.println(String.format("增加了%d条", r));

		} catch (Exception e) {
			System.out.println(e);
		} finally {
			try {
				stm.close();
			} catch (SQLException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
			try {
				con.close();
			} catch (SQLException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}

		}
	}
}
